package com.ham.mud.state;

import com.ham.mud.ServerConnection;
import com.ham.mud.TargetableService;
import com.ham.mud.commands.LookCommand;

import java.util.Arrays;
import java.util.Random;

/**
 * Created by hlucas on Jul 18, 2011 at 8:48:57 AM
 */
public class RestingState extends ConnectionState {
    int regenTicker = 0;
    private static Random rand = new Random();

    public RestingState(ServerConnection connection) {
        super(connection);
    }

    @Override
    public void processInput(String line) {
        String target = TargetableService.findTarget(line, Arrays.asList("wake", "rest", "stand"));
        if(target != null) {
            connection.printSolo("You stop resting and stand up.");
            connection.changeState(new PlayingState(connection));
            new LookCommand().execute(connection);
        } else {
            connection.printSolo("You can't do that while resting.");
        }
    }

    @Override
    public void tick() {
        regenTicker++;

        if(regenTicker == 15) {
            connection.getPlayer().regen(connection);
            regenTicker = 0;
        }
    }
}
